/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#include <mariana-trench/PartiallyFulfilledExploitabilityRuleState.h>

namespace marianatrench {

void PartiallyFulfilledExploitabilityRuleState::add_source_as_transform_sinks(
    const IRInstruction* instruction,
    const Taint& source_as_transform_sinks) {
  auto sink_iterator =
      instruction_to_source_as_transform_sinks_.find(instruction);
  if (sink_iterator == instruction_to_source_as_transform_sinks_.end()) {
    LOG(5,
        "Adding partially fulfilled source-as-transform sink: {} at instruction: {}",
        source_as_transform_sinks,
        show(instruction));
    instruction_to_source_as_transform_sinks_.emplace(
        instruction, source_as_transform_sinks);
  } else {
    LOG(5,
        "Updating partially fulfilled source-as-transform sink: {} at instruction: {}",
        source_as_transform_sinks,
        show(instruction));
    sink_iterator->second.join_with(source_as_transform_sinks);
  }
}

Taint PartiallyFulfilledExploitabilityRuleState::source_as_transform_sinks(
    const IRInstruction* instruction) const {
  auto sink_iterator =
      instruction_to_source_as_transform_sinks_.find(instruction);
  if (sink_iterator == instruction_to_source_as_transform_sinks_.end()) {
    return Taint::bottom();
  }

  return sink_iterator->second;
}

} // namespace marianatrench
